package com.wanshi.controller;

import com.wanshi.entity.AdminUser;
import com.wanshi.mapper.AdminUserMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: wb
 * @CreateTime: 2023-03-07  14:13
 * @Description:
 */
@RestController  // @controller 和 @ResponseBody
@RequestMapping("/admin")
//@CrossOrigin  // 解决跨域
public class AdminUserController {
    @Value("${server.port}")
    private String port;
    @Resource
    private AdminUserMapper adminUserMapper;


    // restfull 的风格
    @GetMapping("/getUser/{id}") // delete
    public  String getUser(@PathVariable("id") String admin_id){
        // 根据主键查询用户
        AdminUser adminUser = adminUserMapper.selectByPrimaryKey(admin_id);
        System.out.println(adminUser+port);
        return port+admin_id;
    }
    // 返回一个可用,假的,先别报错
//    @GetMapping("/getadmin/{id}") // delete
    @RequestMapping("/getadmin/{id}") // d
    public  AdminUser getadmin(@PathVariable("id") String admin_id) throws InterruptedException {
        Thread.sleep(2000);
        if ("2".equals(admin_id)) {
            throw new NullPointerException("空指针");
        }
        // 根据主键查询用户
        AdminUser adminUser = adminUserMapper.selectByPrimaryKey(admin_id);
        System.out.println(adminUser+port);
        return adminUser;
    }
}
